<template>
  <div class="create-project">
    <common-breadcrumb :crumb="crumb"></common-breadcrumb>
    <el-card>
      <el-form
        :model="createProjectForm"
        :rules="createProjectRules"
        ref="createProjectRef"
        label-width="100px">
        <el-form-item label="项目名称" prop="project_name">
          <el-input v-model="createProjectForm.project_name"></el-input>
        </el-form-item>
        <el-form-item label="项目描述" prop="project_desc">
          <el-input v-model="createProjectForm.project_desc"></el-input>
        </el-form-item>
        <el-form-item label="项目产品经理" prop="project_pm">
          <el-input v-model="createProjectForm.project_pm"></el-input>
        </el-form-item>
        <el-form-item label="项目程序员" prop="project_programmer">
          <el-input v-model="createProjectForm.project_programmer"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="medium" @click="createProject">添加</el-button>
        </el-form-item>
       </el-form>
    </el-card>
  </div>
</template>

<script>
import commonBreadcrumb from '../../components/common/Breadcrumb'
export default {
  components: {
    commonBreadcrumb
  },
  data () {
    return {
      crumb: ['管理', '添加项目'],
      createProjectForm: {
        project_name: '',
        project_desc: '',
        project_pm: '',
        project_programmer: ''
      },
      createProjectRules: {
        project_name: [
          { required: true, message: '项目名称必填', trigger: 'blur' },
          { max: 50, message: '该字段最多50个字符', trigger: 'blur' }
        ],
        project_programmer: [
          { required: true, message: '程序员员必填', trigger: 'blur' },
          { max: 20, message: '该字段最多20个字符', trigger: 'blur' }
        ],
        project_desc: [
          { max: 255, message: '该字段最多255个字符', trigger: 'blur' }
        ],
        project_pm: [
          { max: 20, message: '该字段最多20个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    createProject () {
      this.$refs.createProjectRef.validate(async valid => {
        if (valid) {
          const { data: res } = await this.$axios.post('projectlist', this.createProjectForm)
          if (res.code === 1) {
            this.$message.success('添加成功')
            return false
          }
          this.$message.error('添加失败')
        }
      })
    }
  }
}
</script>
